package com.igeek.javase.relation.game;

/**
 * @author chenmin
 * 2023/7/13 17:36
 * @description TODO
 */
public class Hero extends Role{

    //一个英雄可以有三个装备  关联关系：一对多
    private Equipments[] equipments = new Equipments[3];
    //统计装备数量
    private int index;


    public Hero() {
    }

    public Hero(String name, int level, int blood, int power, int defence, String kind) {
        super(name,level,blood,power,defence,kind);
    }

    public Hero(Equipments[] equipments, int index) {
        this.equipments = equipments;
        this.index = index;
    }

    @Override
    //攻击方法
    public void attack(Role role){
        //有一定几率打出暴击率
        int n = (int)(Math.random()*10+1);
        int block = 0;
        if(n>=3){
            block = n*3;
        }

        //怪兽的失血量 = 英雄攻击力 + 暴击伤害 - 怪兽的防御力
        int blood = getPower() +block - role.getDefence();
        if(blood>0){
            role.setBlood(role.getBlood() - blood);
            System.out.println("当前怪兽失血量为："+blood+"，剩余血量："+role.getBlood());
        }else{
            System.out.println("此回合攻击无效");
        }
    }

    //添加装备的方法
    public void addEquip(Equipments e){
        if(index>=equipments.length){
            System.out.println("装备已满~");
            return;
        }
        equipments[index++] = e;
        //添加装备，合并装备的攻击力
        this.setPower(this.getPower() + e.getPower());
        //添加装备，合并装备的防御力
        this.setDefence(this.getDefence() + e.getDefence());
    }

    //显示信息的方法
    @Override
    public void show(){
        System.out.println("英雄的名称："+getName());
        System.out.println("英雄的等级："+getLevel());
        System.out.println("英雄的血量："+getBlood());
        System.out.println("英雄的攻击力："+getPower());
        System.out.println("英雄的防御力："+getDefence());
        System.out.println("英雄的类别："+getKind());

        System.out.println("---------英雄装备的信息----------");
        if(equipments!=null){
            for (int i = 0; i < equipments.length; i++) {
                if(equipments[i]!=null){
                    equipments[i].show();
                }
            }
        }
    }

    public Equipments[] getEquipments() {
        return equipments;
    }
    public void setEquipments(Equipments[] equipments) {
        this.equipments = equipments;
    }

    /**
     * 获取
     * @return index
     */
    public int getIndex() {
        return index;
    }

    /**
     * 设置
     * @param index
     */
    public void setIndex(int index) {
        this.index = index;
    }

    public String toString() {
        return "Hero{equipments = " + equipments + ", index = " + index + "}" + super.toString();
    }

}
